package io.renren.modules.course.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.course.entity.DirectionEntity;
import io.renren.modules.course.service.DirectionService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 方向列表
 *
 * @author zlb
 * @email 316682546@qq.com
 * @date 2018-07-04 09:29:28
 */
@RestController
@RequestMapping("course/direction")
public class DirectionController {
    @Autowired
    private DirectionService directionService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("course:direction:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = directionService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("course:direction:info")
    public R info(@PathVariable("id") Integer id){
        DirectionEntity direction = directionService.selectById(id);

        return R.ok().put("direction", direction);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("course:direction:save")
    public R save(@RequestBody DirectionEntity direction){
        directionService.insert(direction);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("course:direction:update")
    public R update(@RequestBody DirectionEntity direction){
        ValidatorUtils.validateEntity(direction);
        directionService.updateAllColumnById(direction);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("course:direction:delete")
    public R delete(@RequestBody Integer[] ids){
        directionService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
